<!DOCTYPE HTML>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
		<meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
		<link rel="stylesheet" type="text/css" href="../../css/style.css" />
		<style type="text/css">
			html,body{
				background-color: transparent !important;
			}
			.info_box{ position: fixed; left: 0; bottom: 0; width:100%; height: 260px; background-color: #fff; box-sizing: border-box; padding: 0; z-index: 12;}
			.info_box .top{
				display: flex;
				justify-content: space-between;
				background: #f5f5f5;
			}
			.info_box .top div { font-size: 15px; padding:0 10px; font-weight:600; color:#72757A; height: 50px; line-height: 50px; }
			
			.a-active { color:#3262F1 !important; }
		</style>
	</head>
	<body>
		<div id="filter" style="height:100%;">
		<div id="content">
		<!--完善信息弹窗start-->
		<div class="info_box">
			<div class="top">
				<div tapmode="a-active" onclick="closeframe()">取消</div>
				<div></div>
				<div tapmode="a-active" style="color:#3262F1" onclick="settime()">完成</div>
			</div>
		</div>
		<!--完善信息弹窗end-->
		</div>
		</div>
	</body>
	<script type="text/javascript" src="../../script/api.js" ></script>
	<script type="text/javascript" src="../../script/app.js" ></script>
	<script type="text/javascript">
		var fromwin = '';
		var content = '今天 全天 (00:00-24:00)'; //当前提交内容
		var todaytime =	new Date(
			new Date(new Date().toLocaleDateString()).getTime()
		); 
		todaytime = Math.round(todaytime / 1000).toString();
		var jsoncontent = {
			content: '',
			timestrap: todaytime,
			timetype: 0
		};
		var curdateval = [{value:"今天",timestrap:todaytime},{value:"全天 (00:00-24:00)",timetype:0}];
		var timearr = [
			[{value:"都可以",timetype:-1},{value:"7:00",timetype:7},{value:"8:00",timetype:8},{value:"9:00",timetype:9},{value:"10:00",timetype:10},{value:"11:00",timetype:11},{value:"12:00",timetype:12}],
			[{value:"都可以",timetype:-1},{value:"13:00",timetype:13},{value:"14:00",timetype:14},{value:"15:00",timetype:15},{value:"16:00",timetype:16},{value:"17:00",timetype:17},{value:"18:00",timetype:18}],
			[{value:"都可以",timetype:-1},{value:"19:00",timetype:19},{value:"20:00",timetype:20},{value:"21:00",timetype:21},{value:"22:00",timetype:22},{value:"23:00",timetype:23}],
			[{value:"都可以",timetype:-1},{value:"00:00",timetype:0},{value:"1:00",timetype:1},{value:"2:00",timetype:2},{value:"3:00",timetype:3},{value:"4:00",timetype:4},{value:"5:00",timetype:5},{value:"6:00",timetype:6}],
		];
		var datearr = [];
		apiready = function() {
			api.parseTapmode();
			fromwin = api.pageParam.fromwin;
			for(var i=0;i<7;i++)
			{
				var curval = getDay(i);
				if(i==0)
				{
					curval.value = '今天';
				}
				else if(i==1)
				{
					curval.value = '明天';
				}
				datearr.push(curval);
			}
			
			selTime();
			//点击空白处移除Frame
			var myDiv = document.getElementById("filter");
			myDiv.addEventListener("touchstart",function(){
				//api.setFrameAttr({
					//name: 'settime_frm',
					//hidden: true
				//});
				api.closeFrame({
					name: 'settime_frm'
				});
				
			});
			var myDiv1 = document.getElementById("content");
			myDiv1.addEventListener("touchstart",function(event){
				event=event||window.event;
				event.stopPropagation();
			});
			
			
		}
		function closeframe() {
			api.closeFrame({
				name: 'settime_frm'
			});
			//api.setFrameAttr({
				//name: 'settime_frm',
				//hidden: true
			//});
		}
		function settime() {
			api.execScript({
				name: fromwin+'_win',
				//frameName: fromwin+'_frm',
				script: 'setloadtime(\''+$api.jsonToStr(jsoncontent)+'\');'
			});
			closeframe();
		}
		function getDay(day){
			
			var today = new Date();
			var targetday_milliseconds=today.getTime() + 1000*60*60*24*day;
			today.setTime(targetday_milliseconds); //注意，这行是关键代码
			var tYear = today.getFullYear();
			var tMonth = today.getMonth();
			var tDate = today.getDate();
			tMonth = doHandleMonth(tMonth + 1);
			tDate = doHandleMonth(tDate);
			//return tMonth+"月"+tDate+"日";
			//return tYear+"-"+tMonth+"-"+tDate;
			var trandate = Date.parse(new Date(tYear+"-"+tMonth+"-"+tDate+" 00:00:00"))||Date.parse(new Date(tYear+"/"+tMonth+"/"+tDate+" 00:00:00"));
			var ret = {
				value: tMonth+"月"+tDate+"日",
				timestrap: Math.round(trandate/1000).toString()
			};
			return ret;
		}
		function doHandleMonth(month){
			var m = month;
			if(month.toString().length == 1){
			 m = "0" + month;
			}
			return m;
		}
 
		function selTime() {
			//选择时间
			var UICustomPicker = api.require('UICustomPicker');
			UICustomPicker.open({
				rect: {
					x: 0,
					y: api.frameHeight  - 210,
					w: api.frameWidth -0,
					h: 210
				},
				styles: {
					bg: '#fff',
					normalColor: '#A4ABB0',
					selectedColor: '#403D3D',
					selectedSize: 18,
					tagColor: '#000',
					tagSize: 20
				},
				data: [{
					tag: '',
					scope: datearr
				}, {
					tag: '',
					scope: [{value:"上午",index:0},{value:"下午",index:1},{value:"晚上",index:2},{value:"凌晨",index:3}]
				}, {
					tag: '',
					scope: [{value:"都可以",timetype:-1},{value:"7:00",timetype:7},{value:"8:00",timetype:8},{value:"9:00",timetype:9},{value:"10:00",timetype:10},{value:"11:00",timetype:11}]
				}],
				rows: 6,
				autoHide: false,
				fixedOn: api.frameName,
				fixed: true
			}, function(ret, err) {
				//alert(JSON.stringify(ret));
				if (ret.eventType == "selected") {
					alert(JSON.stringify(ret));
					var curday = ret.data[0];
					var curshiduan = ret.data[1];
					content = curday.value + ' '+curshiduan.value;
					//jsoncontent.content = content;
					//jsoncontent.timestrap = curday.timestrap;
					//jsoncontent.timetype = curshiduan.timetype;
					
				}
				if (ret.eventType == "show") {
					UICustomPicker.setValue({
						id: ret.id,
						data: curdateval
					});
					
				}
			});
		}
	</script>
</html>